package com.zhy.baselibrary.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import com.zhy.baselibrary.base.BaseFragment

class BaseViewPagerFragmentAdapter : FragmentStateAdapter {
    private var fragments:Array<in BaseFragment<*, *>>

    constructor(fragments: Array<BaseFragment<*,*>>, fragmentActivity: FragmentActivity) : super(
        fragmentActivity
    ) {
        this.fragments = fragments
    }

    constructor(fragments: Array<BaseFragment<*,*>>, fragment: Fragment) : super(fragment) {
        this.fragments = fragments
    }

    constructor(
        fragments: Array<BaseFragment<*,*>>,
        fragmentManager: FragmentManager,
        lifecycle: Lifecycle
    ) : super(fragmentManager, lifecycle) {
        this.fragments = fragments
    }



    override fun createFragment(position: Int): BaseFragment<*,*> {
        return fragments[position] as BaseFragment<*, *>
    }

    override fun getItemCount(): Int {
        return fragments.size
    }
}